package com.maserb.monitor.repository.schoolOrg;

import com.maserb.monitor.entity.UserEntity;
import com.maserb.monitor.entity.schoolOrg.SchoolUserOrgEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SchoolUserOrgRepository extends JpaSpecificationExecutor<SchoolUserOrgEntity>
        , PagingAndSortingRepository<SchoolUserOrgEntity, String> {
    List<SchoolUserOrgEntity> findByUser(UserEntity user);

    @Query(value = "select u from SchoolUserOrgEntity uo left join uo.user u left join uo.org o where o.id=?1")
    List<UserEntity> findByOrg(String clazzId);

    @Query(value = "select u from SchoolUserOrgEntity uo left join uo.user u left join uo.org o where o.id=?1 and u.role=?2")
    List<UserEntity> findUserByOrgAndRole(String clazzId, String roleId);
}